package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: zhaoss
 * @Date: 2023/4/29 - 04 - 29 - 16:04
 * @Description: com.sky.controller.admin
 * @version: 1.0
 */

@RestController("adminCategoryController")
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜品以及套餐分类接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    /**
     * 分页查询菜品套餐
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询菜品套餐方法")
    public Result page(CategoryPageQueryDTO dto){
        log.info("分页查询菜品套餐：{}",dto);
        return categoryService.page(dto);
    }


    /**
     * 新增分类
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增分类方法")
    public Result add(@RequestBody CategoryDTO dto){
        log.info("新增分类：{}",dto);

        return categoryService.add(dto);
    }


    /**
     * type查询
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "type查询方法")
    public Result getById(Integer type ){
        log.info("type查询：{}",type);

        return categoryService.getByType(type);
    }

    /**
     * 修改
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改方法")
    public Result put(@RequestBody CategoryDTO dto){
        log.info("修改方法：{}",dto);

        return categoryService.put(dto);
    }

    /**
     * 修改分类状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation(value = "修改分类状态方法")
    public Result updateEmpStatus(@PathVariable Integer status,Long id){
        log.info("修改分类状态：{}",status);

        return categoryService.updateEmpStatus(status,id);
    }

    /**
     * 删除
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "删除方法")
    public Result delete(Long id){
        log.info("删除：{}",id);

        return categoryService.delete(id);
    }


}
